//
//  HRDynamicMessageCell.m
//  Hear
//
//  Created by mac on 2017/5/20.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HRDynamicMessageCell.h"
#import "HRCoverImageModel.h"
#import "HRCoverTimeModel.h"
#import "NSMutableAttributedString+GDAttString.h"
@interface HRDynamicMessageCell ()
@property (nonatomic, strong)UIImageView *iconImageView;
@property (nonatomic, strong)UILabel *contentLabel;
@property (nonatomic, strong)UILabel *timeLabel;
@property (nonatomic, strong)UILabel *circleLabel;
@property(nonatomic, strong)UILabel *lineLabel;

@end
@implementation HRDynamicMessageCell

-(void)setModel:(HRDynamicNotificationModel *)model{
    WeakSelf
    
    if (model.iconColor.length){
        [HRCoverImageModel OriginImage:[UIImage imageNamed:model.icon] scaleToSize:CGSizeMake(40, 40) callBackOriginImage:^(UIImage *originImage) {
            weakSelf.iconImageView.image = originImage;
        }];
        self.iconImageView.backgroundColor = [UIColor colorWithHexString:model.iconColor];
    }else{
        [self.iconImageView.layer setImageWithURL:[NSURL URLWithString:model.icon] placeholder:[UIImage imageNamed:@""]];
    }
    
    
    
//    self.contentLabel.attributedText = [NSMutableAttributedString arrtLabelText:model.message arrFont:CustomUIFont(14) attColor:CustomColor(28, 190, 160, 1) lineLengh:0 alignment:0 colorLenghFrom:0 colorLengh:model.nickName.length];
    
    self.contentLabel.text = model.message;
    
    self.timeLabel.text = [HRCoverTimeModel covetTime:model.postTime];
    
    self.circleLabel.hidden = [model.isRead intValue];
    
}
+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *cellID = @"HRDynamicMessageCell";
    
    HRDynamicMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if(!cell){
        cell = [[HRDynamicMessageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self)
    {
        CGFloat pading = 10;
        WeakSelf
        self.iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(pading, pading, 50, 50)];
        self.iconImageView.contentMode = UIViewContentModeScaleAspectFill;
        self.iconImageView.clipsToBounds = YES;
        self.iconImageView.layer.cornerRadius = self.iconImageView.width/2;
        [self addSubview:self.iconImageView];
        self.iconImageView.userInteractionEnabled = YES;
        UITapGestureRecognizer *iconTap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
            if (weakSelf.clickIconBlock){
                weakSelf.clickIconBlock();
            }
        }];
        [self.iconImageView addGestureRecognizer:iconTap];
        
        self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.iconImageView.right+pading, self.iconImageView.top, kFullWidth-self.iconImageView.right-pading*2, 40)];
        self.contentLabel.textColor = [UIColor blackColor];
        self.contentLabel.font = CustomUIFont(14);
        [self addSubview:self.contentLabel];
        self.contentLabel.numberOfLines = 2;
        
        self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.contentLabel.left, self.contentLabel.bottom, self.contentLabel.width, 10)];
        self.timeLabel.textColor = FirstTextColor;
        self.timeLabel.font = CustomUIFont(12);
        [self addSubview:self.timeLabel];
        
        
        self.circleLabel = [[UILabel alloc] initWithFrame:CGRectMake(kFullWidth-20, self.centerY+8, 15, 15)];
        self.circleLabel.textAlignment = 1;
        self.circleLabel.text = @"1";
        self.circleLabel.textColor = [UIColor whiteColor];
        self.circleLabel.font = CustomUIFont(13);
        self.circleLabel.backgroundColor = [UIColor redColor];
        self.circleLabel.layer.cornerRadius = self.circleLabel.width/2;
        self.circleLabel.clipsToBounds = YES;
        [self addSubview:self.circleLabel];
        self.circleLabel.hidden = YES;
        
        
        self.lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.iconImageView.left, 69, kFullWidth-self.iconImageView.left, 1)];
        self.lineLabel.backgroundColor = CustomColor(240, 240, 240, 1);
        [self addSubview:self.lineLabel];
        
    }
    return self;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
